package com.ruoyi.readcard.api.task;

import com.ruoyi.readcard.api.IDReader;
import com.ruoyi.readcard.api.entity.Card;
import com.ruoyi.readcard.util.RestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 定时读取id卡刷卡信息
 */
@Component
public class ReadCardTask {
    @Value("${livenServer.venueUniqueIdentifier}")
    private String venueUniqueIdentifier;

    @Scheduled(fixedRate = 500) // 每秒执行一次
    public void readCard() {
        String carNum = IDReader.read6();

        if (carNum != null && carNum.length() == 10) {
            Card card = new Card(venueUniqueIdentifier,carNum,LocalDateTime.now().toString());
            System.out.println(card.toString());
            // 将消息发给服务平台平台
            RestUtils.postAsync(card);
        }
    }
}
